Graph allows you to display data graphically. It is a
very versatile type of Objects and its usage highly depends on the
imagination of the programmer. Graph class methods allow to put on the
display lines or dots, draw arrays or math functions as curves or
histograms in both linear or logarithmic scales or mixed.
* Type parameters XType and YType. Here we have used the new feature
of C++ - class templates. Class Graph is in effect a template. Type
parameters XType and YType are for type of values on the x-and y-axes.
They can take the next values: double, float, long, int, unsigned
long, unsigned int, char, unsigned char. When declaring the instance
of Graph you have to define the types of axes.
Example:
Graph<int,double> grFourier( ..... );
It means that you can display on the grFourier array of double values
over integer parameter or double function with integer parameter.
Constructor:
Creates Graph with specified parameters. Number of tic marks on the axes is defined by parameters xtics and ytics. The distance between tic marks in VGA pixels is controlled by xpixtic and ypixtic. The type of scale of x or y axes may be of two kinds - linear (LIN) or logarithmic (LOG). In other words we say that x or y axes are in LIN or LOG mode. These modes are set by parameters xscale and yscale when calling the constructor and cannot be changed later. For linear scale you can define the difference between neighbouring tic labels, we call it tic label increment, by xticinc or yticinc parameters. For logarithmic scales these parameters are senseless because the difference in this case is pre-defined as a power 1 of 10, so xticinc or yticinc can take any value.
If the axis is in LIN mode, then the value of displayed data at the
origin of graph ( the origin is the LEFT-BOTTOM corner of Graph's
display ) is defined by xval0 or yval0 as a float point number. If the
scale is logarithmic, then these parameters define the power of 10 at
the origin. It may be a positive or negative integer.
The xtitle and ytitle parameters supply the titles alongside the
axes. The font for these titles is defined by axtitlefont and
axtitlefontsize. You can also customize the font style for tic labels
redefining parameters ticfont and ticfontsize.
Style of grid lines also may be customized by programmer. The gridstyle
parameter provides the bit pattern for grid lines.
Example:
Graph<int,float> grFourier( 0, 0, FIXED, "Fourier transform", // title 24, 18, // number of tic marks 20, 20, // number of pixels between tics 0, min_y, // values of x,y at origin (NumPoints+1)/24., (max_y-min_y)/18.,// increment of tick labels procDummy, // no paint procedure "Frequency","Amplitude",// axes titles "%.0f","%.1f"); // format of tic labels
Data members:
All are inherited from the object base class (sect.4).
Methods:
Includes methods inherited from the object base class (sect.4).
Paints Graph Object with empty display.
Clears the display (we also call it paper), removing all lines, curves and
etc. and repainting the grid.
Repaints the grid lines.
Sets default color of ink. It is a color used to draw dots, lines,
curves, fill rectangles on the graph, when the color parameter is not
specified for the drawing method.
* The color parameter. In the following methods color=-1 means that if
you omit color parameter default ink color will be used. If you don't
omit color parameter then you can specify any of BGI colors.
//— DOT
Paints a single pixel on the paper of graph. The x and y are the
co-ordinates of pixel and must be defined in units of x and y axes.
Example:
for ( i=0; i<NumPoints; i++) grFourier.PutDot( i, y[i], YELLOW);
//— LINE
Paints the line on the paper of graph. The line connects points (x0,y0)
and
(x1,y1) defined in units of x- and y- axes.
Example:
for ( i=0; i<NumPoints-1; i++) grFourier.PutLine( i, y[i], i+1, y[i+1] );
//— FUNCTION
** Note that the function cannot have negative values if y-axis was
set to LOG mode.
Draws math function func with one parameter as a curve. The numpoints
defines the number of samples. More samples means smoother curve and
longer time of drawing. Function is scanned equidistantly from the
origin of x-axis to its end.
Is opposite to ShowCurve - clears out the curve from paper
and redraws the grid.
//— ARRAY
** Note that array elements cannot have negative values if y-axis was
set to LOG mode.
Shows array as a curve on the graph. The numpoints is the number of
elements of array. The x0i and xmaxi are values on the x-axis
associated with correspondingly first and last elements of array. The
elements of array are drawn equidistantly along x-axis. Parts of the
curve lying behind Graph's display are cut out.
Example:
grFourier.ShowCurve( NumPoints, 0, NumPoints-1, y, YELLOW);
Is opposite to ShowCurve - clears out the curve from paper
and redraws the grid.
** If x-axis has been set to LOG mode, calling ShowHistogram
method interrupts the program with the error message:
Graph::ShowHistogram : X-scale cannot be LOG for histogram
Shows array as a histogram. The numpoints is the number of elements of
array. The x0i is the value on the x-axis associated with the first
element of array. The distance between neighbouring bars of histogram
is defined by xstep parameter (in the unit of x-axis). The width of bar is
calculated automatically.
Example:
grFourier.ShowHistogram( NumPoints, 0, 1023 , y );
Is opposite to ShowHistogram - clears out the histogram
from the paper and redraws the grid.
//— TWO ARRAYS
** Note that array elements cannot have negative values if axis was
set to LOG mode.
Arrays must have equal number of elements. Xdata and Ydata arrays
provide coordinates of points of the curve on the graph. The numpoints
is the number of elements of arrays. Parts of the curve lying behind
Graph's display are cut out.
Is opposite to ShowCurve - clears out the curve from the paper
and redraws the grid.
Color schemes:
There are four pre-defined color patterns for Graph:
struct graphcolors // Graph color structure { COLORS Paper, Ink, Grid, Title, AxesTitles, TicLabels ;}; const graphcolors WhiteOnCyan = { CYAN, WHITE, LIGHTCYAN, RED, BLACK, BLUE }, YellowOnCyan = { CYAN, YELLOW, LIGHTCYAN, RED, BLACK, BLUE }; GreenOnBlue = { BLUE, LIGHTGREEN, LIGHTBLUE, RED, BLACK, BLUE }, YellowOnBlue = { BLUE, YELLOW, LIGHTBLUE, RED, BLACK, BLUE };}